<iframe src="<%=excursion_path(@excursion, :format => :full)%>" width="100%" height="99%" style="border:0; height: 99% !important;" iframeborder="0" frameborder="0" iframeElement.frameBorder = 0; webkitAllowFullScreen="true" allowfullscreen="true" mozallowfullscreen="true"></iframe>

<% return unless @gateway %>

<script>
	var gateway = "<%=@gateway%>";

	//Init
	document.body.style.height="100%";

	//Onload
	window.onload = function(){
		VISH.IframeAPI.init({preventDefault: true, callback: onConnect});
	};

	function onConnect(origin){
		// console.log("Communication stablished with " + origin);
		switch(gateway){
			case "mashme":
				var MASHME_API_SCRIPT_URL = "https://www.mashme.tv/static/js/iframe/MashMe.API.iFrame.js";
				$.getScript(MASHME_API_SCRIPT_URL).done(function(script, textStatus){
					MASHME.API.iFrame.init("myappkey","myappsecret", _onMessage);
				});
				break;
			default:
				break;
		}
		VISH.IframeAPI.registerCallback("onMessage",_onVEMessage);
	};

	//_onMessage listen to all messages, both from VE and Web Application.
	var _onMessage = function(message){
		// console.log("_onMessage:" + message.data + " from:" + message.origin);
		try {
			var VEMessage = message.data.split("MashMeAPIMessage:")[1];
			var VEMessageObject = JSON.parse(VEMessage);
			if(typeof VEMessageObject.sent === "boolean"){
				//Received message from Web App
				// console.log("Received message from Web App: iframeAPI send message");
				VISH.IframeAPI.sendMessage(VEMessage);
			}
		} catch(e){
			// console.log("Exception _onMessage");
			// console.log(e)
		}
	};

	var _onVEMessage = function(VEMessage,origin){
		var VEMessageObject = JSON.parse(VEMessage);
		if(typeof VEMessageObject.sent !== "boolean"){
			VEMessageObject.sent = true;
			VEMessage = JSON.stringify(VEMessageObject);
			switch(gateway){
				case "mashme":
					if(typeof MASHME != "undefined"){
						MASHME.API.iFrame.broadcast("MashMeAPIMessage:"+VEMessage);
					}
					break;
				default:
				break;
			}
		}
	};

</script>